<!DOCTYPE html>
<html lang="en">
	<head>
		<title>用户管理</title>
		<#include "../../inc/header.ftl"/>
	</head>

	<body class="no-skin">

		<div class="main-container ace-save-state" id="main-container">

			<div class="main-content">
				<div class="main-content-inner">

					<div class="page-content">
                        <form class="form-horizontal" id="form-add" method="post">
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">旧密码</label>
                                <div class="col-xs-12 col-sm-6">
									<span class="block input-icon input-icon-right">
										<input type="text" name="oldPassword" id="oldPassword" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">新密码</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="newPassword" id="newPassword" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-4 no-padding-right">确认密码</label>
                                <div class="col-xs-12 col-sm-6">
                                    <div class="clearfix">
                                        <input type="text" name="newPassword1" id="newPassword1" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    </div>
                                </div>
                            </div>
                        </form>

                    </div><!-- /.page-content -->
				</div>
                <div style="text-align: center">
                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit"  onclick="javascript:saveInfo()">修改</a>
                </div>
			</div><!-- /.main-content -->
		</div><!-- /.main-container -->

		<!-- basic scripts -->
		<#include "../../inc/basicjs.ftl"/>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
            function saveInfo() {
                var oldpwd = $("#oldPassword").val();
                var pwd = $("#newPassword").val();
                var pwdconfirm = $("#newPassword1").val();

                if(pwd.length<12||pwdconfirm.length<12){
                    alert("密码位数不能低于12位，请重新输入。");
                    return;
                }

                if(pwd!=pwdconfirm){
                    alert("两次输入的密码不一致，请重新输入。");
                    return;
                }
                if(oldpwd==pwd){
                    alert("原密码和新密码一致，请重新输入。");
                    return;
                }

                var reg = /^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d).*$/;
                if(!reg.test(pwd)) {
                    alert("必须包含大小写和数字");
                    return;
                }

                $('#form-add').form({
                    url: prefix +'/sys/user/editPassword',
                    onSubmit:function(){
                        var isValid = $(this).form('validate');
                        if (isValid){
                            $.messager.progress({
                                title: '提示',
                                msg: '数据处理中，请稍候……',
                                text: ''
                            });
                        }
                        return isValid;
                    },
                    success:function(data) {
                        $.messager.progress('close');
                        var data = eval('(' + data + ')');
                        $.messager.alert('提示', data.msg, 'info');
                        if(data.success) {
                            logout();
                        }
                    }
                });
                $('#form-add').submit();
            }


            function logout() {
                $.ajax({
                    url: prefix + "/logout",
                    type:'post',
                    data:{},
                    dataType:'json',
                    async : true,
                    error:function(){

                    },
                    success:function(data){
                        window.location = prefix + "/index/login";
                    }
                });
            }
		</script>
	</body>
</html>
